package com.skiving.cloud.develop.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.solon.service.impl.ServiceImpl;
import com.skiving.cloud.common.utils.PageParameter;
import com.skiving.cloud.develop.entity.SysFormDesigner;
import com.skiving.cloud.develop.mapper.SysFormDesignerMapper;
import com.skiving.cloud.develop.service.SysFormDesignerService;
import org.noear.solon.annotation.Component;
import org.noear.solon.Utils;

import java.util.List;

/**
 * 表单设计表 服务层实现。
 *
 * @author skivingcloud
 * @since 2025-03-25
 */
@Component
public class SysFormDesignerServiceImpl extends ServiceImpl<SysFormDesignerMapper, SysFormDesigner>  implements SysFormDesignerService {
    /**
     * 分页查询表单设计表
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<SysFormDesigner> queryByPage(PageParameter<SysFormDesigner> parameter){
        Page<SysFormDesigner> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (parameter.getParam() != null) {
            //查询条件
            if (Utils.isNotBlank(parameter.getParam().getId())) {
                queryWrapper.and(SysFormDesigner::getId).like(parameter.getParam().getId());
            }
            if (Utils.isNotBlank(parameter.getParam().getFormCode())) {
                queryWrapper.and(SysFormDesigner::getFormCode).like(parameter.getParam().getFormCode());
            }
            if (Utils.isNotBlank(parameter.getParam().getFormName())) {
                queryWrapper.and(SysFormDesigner::getFormName).like(parameter.getParam().getFormName());
            }
            if (Utils.isNotBlank(parameter.getParam().getFormType())) {
                queryWrapper.and(SysFormDesigner::getFormType).like(parameter.getParam().getFormType());
            }
            if (Utils.isNotBlank(parameter.getParam().getRemark())) {
                queryWrapper.and(SysFormDesigner::getRemark).like(parameter.getParam().getRemark());
            }
            if (Utils.isNotBlank(parameter.getParam().getFormDesJson())) {
                queryWrapper.and(SysFormDesigner::getFormDesJson).like(parameter.getParam().getFormDesJson());
            }
        }
        return this.page(page, queryWrapper);
    }

    /**
     * 根据名称查询表单
     *
     * @param formName 名称
     * @return 结果
     */
    @Override
    public List<SysFormDesigner> getFormDesignerByNameLike(String formName){
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SysFormDesigner::getFormName).like(formName);
        return this.list(queryWrapper);
    }

    /**
     * 根据编号获取表单信息
     *
     * @param formCode 表单编号
     * @return 表单信息
     */
    @Override
    public SysFormDesigner getFormDesignerByFormCode(String formCode){
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(SysFormDesigner::getFormCode).eq(formCode);
        return this.getOne(queryWrapper);
    }
}
